﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _organizeid = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
    var _PStructId = "";
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 171.5);
            }, 200);
            e.stopPropagation();
        });

        $("#PStructTree").ComboBoxTree({
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?type=1",
            height: "250px",
            description: "==请选择==",
            click: function (item) {
                if (_PStructId != item.id) {
                    _PStructId = item.id;
                }
            }
        });
        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);

    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["PStructId"] = _PStructId;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        $gridTable.jqGrid({
            url: "/SystemManage/BussinessIndicator/GetList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 171.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'Id', hidden: true },
                { label: '指标Id', name: 'RuleId', hidden: true },
                { label: "指标名称", name: "RuleName", width: 200, align: "center", sortable: false },
                { label: "指标值", name: "Value", width: 100, align: "center", sortable: false },
                {
                     label: "颜色", name: "Color", width: 100, align: "center", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         return "<div style='width:70px;background-color:" + cellvalue + "'>&nbsp;</div>";
                     }
                },
                { label: "统计年份", name: "Year", width: 100, align: "center", sortable: false },
                { label: "统计月份", name: "Month", width: 100, align: "center", sortable: false },
                { label: "统计日期", name: "Date", width: 100, align: "center", sortable: false },
                { label: "计算人", name: "CountUserName", width: 100, align: "center", sortable: false },
                { label: "计算时间", name: "Time", width: 100, align: "center", sortable: false }
            ],
            pager: "#gridPager",
            rowNum: 30,
            rowList: [30, 50, 100],
            sortname: 'Time',
            sortorder: 'desc',
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件设置
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#queryCondition").GetWebControls();
            queryJson["PStructId"] = _PStructId;
            queryJson["OrganizeId"] = _organizeid;
            queryJson["condition"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
            $gridTable.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车事件
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '设置经营指标',
            url: '/SystemManage/BussinessIndicator/RuleIndex',
            width: "1100px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center" style="margin-left:10px;">
        <div class="center-Panel">
            <div class="panel-Title">经营指标</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table id="queryCondition">
                        <tr>
                            <td>
                                <div id="PStructTree" type="selectTree" class="ui-select" style="width: 200px;"></div>
                            </td>
                            <td style="padding-left: 2px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(1 - Convert.ToInt32(DateTime.Now.DayOfYear)).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfYear)).AddYears(1).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">起止时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="@LeSoft.Util.Time.GetDate(1 - Convert.ToInt32(DateTime.Now.DayOfYear))" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'%y-%M-%d'})">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="@DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.DayOfYear)).AddYears(1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({})">
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </td>
                           
                            <td style="padding-left: 2px;">
                                <input id="keyword" type="text" class="form-control" placeholder="请输入指标名称或指标值" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;设置经营指标</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>

                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>